package com.inventory.api.entity;

import com.inventory.api.signUpReq.InvntSignupReq;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * 出入库单
 * Created by lihu on 2018/1/31.
 */
@Entity
@Data
@NoArgsConstructor
public class StockOrder {

    @Id
    @Column(length = 50)
    private String id;

    @Column(length = 50)
    private String storeId;


    private String operatorId;

    private String operatorName;

    /**
     * 入库总金额
     */
    private int totalAmount;

    /**
     * 单据图片地址
     */
    private String bill;

    /**
     * 备注
     */
    private String notes;


    /**
     * 出入库原因
     */
    @Enumerated(EnumType.STRING)
    private StockSource stockSource;

    /**
     * 出入库地址
     */
    @Enumerated(EnumType.STRING)
    private StockType type;

    /**
     * 操作时间
     */
    @Column(columnDefinition = "TIMESTAMP(3) NULL")
    private Date operTime;
    @Column(insertable = false, updatable = false, columnDefinition = "TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3)")
    private Date addTime;


    public StockOrder(InvntSignupReq signupReq, StockType type) {

        id = signupReq.getId();
        storeId = signupReq.getStoreId();
        operatorId = signupReq.getOperatorId();
        operatorName = signupReq.getOperatorName();
        totalAmount = signupReq.getTotalAmount();
        bill = signupReq.getBill();
        notes = signupReq.getNotes();
        stockSource = signupReq.getStockSource();
        this.type = type;
        operTime = new Date();
    }

}
